package servlets;

import java.io.IOException;
import java.sql.*;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import by.grsu.hdm.HomeDeviceManagerStarter;
import by.grsu.hdm.devices.MediaCenter;
import by.grsu.hdm.devices.UsbFlashDrive;
import by.grsu.hdm.media.MediaPlayer;
import by.grsu.hdm.media.Track;


/**
 * Servlet implementation class MainServlet
 */
@WebServlet("/MainServlet")
public class MainServlet extends HttpServlet {     
   	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 if(request.getParameter("action").equals("browse")){
			HomeDeviceManagerStarter hms=new HomeDeviceManagerStarter();
			MediaCenter media=hms.Starter();
			 HttpSession session = request.getSession(true);
			 session.setAttribute("media", media);
			 request.setAttribute("tracks", ((UsbFlashDrive) media.getUsbPort().getConnectedDevice()).getTracks());
			 request.getRequestDispatcher("Browse.jsp").forward(request, response);	  
		  } 
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	doGet(request,response);
	}
}


